package com.example.its2020008;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class register extends AppCompatActivity {


    private TextView tvMainTitle;
    private EditText edtTxtMainAccount;
    private EditText edtTxtMainPsw;
    private EditText edtTxtMainPsw1;
    private Button btnMainRegister;
    private Button btnMainBack;
    private String account, psw, psw1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        //设置界面为竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    private void init() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        edtTxtMainAccount = (EditText) findViewById(R.id.edtTxt_main_account);
        edtTxtMainPsw = (EditText) findViewById(R.id.edtTxt_main_psw);
        edtTxtMainPsw1 = (EditText) findViewById(R.id.edtTxt_main_psw1);
        btnMainRegister = (Button) findViewById(R.id.btn_main_register);
        btnMainBack = (Button)findViewById(R.id.btn_main_back) ;
        btnMainRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String straccount = edtTxtMainAccount.getText().toString().trim();
                String strpsw = edtTxtMainPsw.getText().toString().trim();
                String  strpsw1 = edtTxtMainPsw1.getText().toString().trim();
                if ((!straccount.equals(null))&&(!strpsw.equals(null))&&(!strpsw1.equals(null))){
                    Toast.makeText(register.this, "恭喜，注册成功！",
                            Toast.LENGTH_LONG).show();
                }
                if (TextUtils.isEmpty(account)) {
                    Toast.makeText(register.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                    return;
                } else if (TextUtils.isEmpty(psw)) {
                    Toast.makeText(register.this, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                } else if (TextUtils.isEmpty(psw1)) {
                    Toast.makeText(register.this, "请再次输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }else if(!psw.equals(psw1)){
                    Toast.makeText(register.this, "输入两次的密码不一样", Toast.LENGTH_SHORT).show();
                    return;

                }else{
                    Toast.makeText(register.this, "注册失败", Toast.LENGTH_SHORT).show();
                    Intent data = new Intent();
                    data.putExtra("userName",account);
                    setResult(RESULT_OK, data);
                    register.this.finish();
                }
            }
        });
        btnMainBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

}
